﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Utils;

namespace UI.ModSalary
{
    public partial class SalaryBatch : System.Web.UI.Page
    {
        DefDicBiz defDicBiz = new DefDicBiz();
        SalaryTableBiz salaryTableBiz = new SalaryTableBiz();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            string setsID = "";
            string strYear = "";
            string strMonth = "";
            if (Request.Params["SetsID"] != null)
            {               
                setsID = Request.Params["SetsID"].ToString();
                strYear = Request.Params["StrYear"].ToString();
                strMonth = Request.Params["StrMonth"].ToString();
            }
            if (strYear == "" || strMonth == "")
            {
                JSUtility.Alert(this, "参数错误 ");
                return;
            }
            if (!IsPostBack)
            {
                defDicBiz.InitXMLDropDownList(ddlYear, "YearList.xml", strYear);
                defDicBiz.InitXMLDropDownList(ddlMonth, "MonthList.xml", strMonth);
                
                defDicBiz.InitDropDownList("Wage_Sets", ddlSetsID, setsID);

                JSUtility.AddConfirm(btnAdd, "您真的要修改工资项吗？\n有可能导致重新生成工资表，请联系系统管理员再进行操作！");
                 ddlSetsItem.DataSource = new SetsItemBiz().GetItemList(setsID);
                 ddlSetsItem.DataTextField = "ItemName";
                 ddlSetsItem.DataValueField = "WageItem";// "WageItem";
                 ddlSetsItem.DataBind();
            
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string strYear = ddlYear.SelectedValue;
            string strMonth = ddlMonth.SelectedValue;          
            string setsID = ddlSetsID.SelectedValue;
          
            //1
            string wageItem = ddlSetsItem.SelectedValue;
            //2
            string empRange = string.Empty;
            if (rbAll.Checked) empRange = "All";
            else if (rbManager.Checked) empRange = "Manager";
            else empRange = "Emp";
            //3
            string isAdd=string.Empty;
            if (rbz.Checked) isAdd = "Yes";
            else isAdd = "No";
            //4
            string num="0";
            //5
            string modiWay = string.Empty;
            if (rbMoney.Checked)
            {
                num = txtNum.Text;
                modiWay = "isNumber";
            }
            else if (rbDouble.Checked)
                modiWay = "isDouble";
            else if (rbThree.Checked)
                modiWay = "isThree";           
            else
                return;

            if (salaryTableBiz.AddSalary(setsID, strYear, strMonth, wageItem, empRange, isAdd, modiWay, num))
            {
               
                    salaryTableBiz.ReCau(setsID, "", strYear, strMonth);
               
                JSUtility.Alert(this,"操作成功");
            }
            else JSUtility.Alert(this, "操作失败");
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            JSUtility.CloseWindow();
        }

        protected void btnYear_Click(object sender, EventArgs e)
        {
            
            Response.Redirect("SalaryYearEnd.aspx");
        }
    }
}